<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet"
	href='<c:url value="/share/bootstrap.css"></c:url>'>
<link rel="stylesheet"
	href='<c:url value="/share/AllStyle.css"></c:url>'>
<script src='<c:url value="/js/jquery.min.js"></c:url>'></script>
<script src='<c:url value="/js/bootstrap.min.js"></c:url>'></script>
<script src='<c:url value="/js/boot.js"></c:url>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<script src='<c:url value="/js/all.js"></c:url>'></script>
	<style>
		html,body{
			background: #fff;
  			font-family: "Microsoft YaHei";
		}
		.content_Answer_score{
			width: 1190px;
			margin: 0 auto;
			padding-top: 25px;
		}
		.content_Answer_score_title{
			position: relative;
			overflow: hidden;
			color: #2b5eae;
			border-bottom: 2px solid #2b5eae;
			line-height: 40px;
		}
		.content_Answer_score_title>span{
			float: left;
  			font-size: 18px;
		}
		.content_Answer_score_title>ul{
			float: right;
		}
		.content_Answer_score_title>ul>li{
			float: left;
			line-height: 30px;
			width: 70px;
			margin-right: 25px;
			text-align: center;
			border-radius: 3px;
			cursor: pointer;
  			font-size: 14px;
  			margin-top: 5px;
		}
		.content_Answer_score_title>ul>li:hover{
			background: #82bcff;
			color: #fff;
		}
		.content_Answer_score_NameTime{
			position: relative;
			overflow: hidden;
			background: #f9f9f9;
			width: 990px;
			line-height: 55px;
			margin-top: 30px;
			margin-bottom: 35px;
			padding: 0 20px;
			border: 1px solid #d7d7d7; 
		}
		.content_Answer_score_NameTime>div{
			float: left;
			font-size: 16px;
			color: rgb(52, 52, 52);
		}
		.content_Answer_score_Name{
			margin-right: 110px;
		}
		.form-control{
			margin: 0 auto;
			margin-top: 10px;
			width: 70px;
			height: 30px;
		}
		.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
			border-bottom: 1px solid #8ac0ff;
			font-size: 16px;
		}
		.content_Answer_score_Table .table tbody tr:last-child(1){
			border-bottom: 0;
		}
		.content_Answer_score_Table .table tbody tr th,.content_Answer_score_Table .table tbody tr td{
			line-height: 50px;
			padding: 0;
			font-size: 16px;
			text-align: center;
		}
		.table>thead>tr>th{
			line-height: 40px;
			padding: 0;
			text-align: center;
		}
		.content_Answer_score_Table .table tbody tr:nth-child(2) td{
			color: #fc2929;
		}
		.content_Answer_score_Table{
			border-bottom: 1px solid #8ac0ff;
			margin-bottom: 30px;
		}
		.content_Answer_score_Table .table{
			margin-bottom: 0;
		}
		.content_Answer_score_list{
			border-top: 1px dashed #295c96;
		}
		.Examination_list_title {
		    border: 1px solid #a4a4a4;
		    line-height: 50px;
		}
		.content_Answer_score_list>ul>li .Examination_list_title:nth-child(1)>span {
		    background: #295c96;
		    color: #fff;
		    padding: 0px 6px;
		    margin: 0 15px;
		    border-radius: 50%;
		}
		.content_Answer_score_list,.content_Answer_score_list>ul{
			position: relative;
			overflow: hidden;
		}
		.content_Answer_score_list>ul>li{
			margin-top: 30px;
		}
		.content_Answer_score_list>ul>li .Examination_list_title{
			margin-bottom: 20px;
		}
		.content_Answer_score_list>ul>li .Examination_list_title:last-child(1){
			margin-bottom: 0;
		}
		.Examination_list_title_rightKey{
			position: relative;
			overflow: hidden;
		}
		.Examination_list_title_rightKey>div:nth-child(1){
			width: 110px;
			line-height: 55px;
			float: left;
			text-align: center;
		}
		.Examination_list_title_rightKey>div:nth-child(2){
			width: 1078px;
			margin-top: 15px;
			margin-bottom: 15px;
			padding-right: 10px;
			line-height: 25px;
			float: left;
			text-align: left;
		}
	</style>
</head>
<body>
	<div class="content_Answer_score">
		<div class="content_Answer_score_title">
			<span>试卷解答题评分</span>
			<ul>
				<li onclick="confirm()">确认</li>
				<li onclick="cancle()">取消</li>
			</ul>
		</div>
		<div class="content_Answer_score_NameTime">
			<div class="content_Answer_score_Name"><p id = "name"></p></div>
			<div class="content_Answer_score_Time">做题时间：<font id="answer_time"></font></div>
		</div>
		<div class="content_Answer_score_Table">
			<table class="table">
		    	<thead style="background: #8ac0ff; color: #fff;">
			        <tr>
			          <th></th>
			          <th>单选题</th>
			          <th>多选题</th>
			          <th>判断题</th>
			          <th>解答题</th>
			          <th>合计</th>
			        </tr>
			    </thead>
		      <tbody>
		        <tr id="each_score">
		        </tr>
		        <tr id="each_count">
		         
		        </tr>
		        <tr id="score">
		         
		        </tr>
		      </tbody>
		    </table>
		</div>
		<div class="content_Answer_score_list">
			<ul id = "list">
			</ul>
		</div>
	</div>
	<script>
		$(function(){
			var value,AnswerQuestions;
			$(".content_Answer_score_list ul li div div input.form-control").keyup(function(){
				//获取输入的值
				var value = $(this).val();
				var AnswerQuestions = $("#Content_Answer_Questions").html();
			});
		})
	</script>
	<script type="text/javascript">
	mini.parse();
	mini_debugger = false;
	var id = "${id}";
	var examId = '${examId}';
	var rootPath = '${rootPath}';
	var score;
	var paperData = new Object;
	var number = 0;
	var isPass = 0;
	var answer="";
	var rightAnswer="";
	var score1,score2,score3;
	var one1=much1=judge1=0;
	$(function(){
		
		getInfor();
	})
	//获取改考生答的试卷信息
	function getInfor(){
		var url = rootPath + "/testPaper/paperInfo/"+examId;
		$.ajax({
			url : url,
			method : "post",
			dataType : "json",
			data : {},
			success : function(data) {
				if (data) {
					console.log(data);
					paperData = data;
					show(data);
					getMap();
					getTestIdList();
				} else {
					mini.alert("获取信息失败！");
				}
			},
			error : function() {
				mini.alert("失败！");
			}
		});
	}
	//获取试卷是信息
	function getMap(){
		var url = rootPath +'/correctPapers/infoData/' +id;
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			success:function(data){
				if(data){
					var time = data.answerTime.replace("T"," ") + "——" + data.submitTime.replace("T"," ")
					$("#answer_time").html(time);
					$("#name").html("答题人："+data.nickname);
					answer = data.answer;
					rightAnswer = data.rightAnswer;
					calculate(rightAnswer,answer);
				}
			}
		});
	}
	//获取试卷试题
	function getTestIdList() {
		var url = rootPath + "/testPaper/testList/" + examId;
		$.ajax({
			url : url,
			method : "post",
			dataType : "html",
			data : {},
			success : function(data) {
				if (data) {
					getTestList(data);
				} else {
					//alert("获取信息失败！");
				}
			},
			error : function() {
				mini.alert("失败！");
			}
		});
	}
	function getTestList(id) {
		var url = rootPath + "/testPaper/questionListData";
		$.ajax({
			url : url,
			method : "post",
			dataType : "json",
			data : {'data':id},
			success : function(data) {
				if (data) {
					showTest(data);
				} else {
					mini.alert("获取信息失败！");
				}
			},
			error : function() {
				mini.alert("失败！");
			}
		});
	}
	//展示简答题
	function showTest(data) {
		var htmStr="";
		var id=0;
		length = data.length;
		answer = answer.split("_kahsdkf_fsd!~&*_");
		for(var i = 0; i < length; i++){
			if(data[i].class_id == "解答题") {
				id++;
				number++;
				htmStr +="<li><div class=\"Examination_list_title\">"
					+"<span style=\"background: #295c96; color: #fff;padding: 0px 6px;border-radius: 50%;\">"+id+"</span>"
					+"<font>"+data[i].question+"</font></div>"
				+"<div class=\"Examination_list_title Examination_list_title_rightKey\">"
					+"<div>正确答案：</div>"
					+"<div>"+data[i].answer+"</div>"
				+"</div>"
				+"<div class=\"Examination_list_title Examination_list_title_rightKey\">"
					+"<div>考生答案：</div>"
					+"<div>"+answer[i]+"</div>"
				+"</div>"
				+"<div class=\"Examination_list_title Examination_list_title_rightKey\">"
					+"<div><sup style=\"color: #fc2929;\">*</sup>评分：</div>"
					+"<div>"
						+"<input type=\"text\" onchange = \"calculate('"+rightAnswer+"','"+answer+"')\" id = \"solution_score_"+id+"\"class=\"form-control\" style=\"float: left;margin-top: 0px;\" onkeyup=\"this.value=this.value.replace(/\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" >";
						<!-- <font style="font-size: 14px;margin-left:15px;color: rgb(175, 175, 175);">按回车确认评分</font> -->
					+"</div>"
				+"</div>"
			+"</li>"
			}
			
		}
		$("#list").html(htmStr);
	}
	//展示试卷试题分数
	function show(data){
		if(!data.one.score){
			data.one.score = 0;
		}
		if(!data.much.score){
			data.much.score = 0;
		}
		if(!data.judge.score){
			data.judge.score = 0;
		}
		if(!data.solution.score){
			data.solution.score = 0;
		}
		var html = "<th scope=\"row\">每题分值</th>"
          +"<td>"+data.one.score+"</td>"
          +"<td>"+data.much.score+"</td>"
          +"<td>"+data.judge.score+"</td>"
          +"<td id=\"Content_Answer_Questions\">"+data.solution.score+"</td>"
          +"<td>"+data.sumScore+"</td>";
		  $("#each_score").html(html);
		var htmlStr = "<th scope=\"row\">题数</th>"
		          +"<td>"+data.one.sum+"</td>"
		          +"<td>"+data.much.sum+"</td>"
		          +"<td>"+data.judge.sum+"</td>"
		          +"<td id=\"Content_Answer_Questions\">"+data.solution.sum+"</td>"
		          +"<td>"+parseInt(data.one.sum+data.much.sum+data.judge.sum+data.solution.sum)+"</td>";
		$("#each_count").html(htmlStr);	 
	}
	function calculate(rightAnswer,answer){
		
		var right = rightAnswer.split("_kahsdkf_fsd!~&*_");
		var orRight = answer.split("_kahsdkf_fsd!~&*_");
		
		for(var i = 0;i<right.length;i++){
			if(right[i] == orRight[i]){
				if(i < paperData.one.sum){
					one1++;
				}else if( i >= paperData.one.sum && i < paperData.one.sum + paperData.much.sum){
					much1++;
				}else{
					judge1++;
				}
			}
		}
		score1 = one1 * paperData.one.score;
		score2 = much1 * paperData.much.score;
		score3 = judge1 * paperData.judge.score;
		score4 = getInputValue();
		score = score1+score2+score3+score4;
		if(score > paperData.score){
			isPass = 1;
		}
		var html = "<th scope=\"row\">得分</th>"
	          +"<td>"+score1+"</td>"
	          +"<td>"+score2+"</td>"
	          +"<td>"+score3+"</td>"
	          +"<td id=\"Content_Answer_Questions\">"+score4+"</td>"
	          +"<td>"+score+"</td>";
		 $("#score").html(html);
	}
	function getInputValue(){
		var value=0;
		for(var i = 1;i<=number;i++){
			var text = $("#solution_score_"+i+"").val();
			var _score = paperData.solution.score;
			if(text > _score){ 
				  text = _score;
				  $("#solution_score_"+i+"").val(_score);
			}
			if(isNaN(text)||!text){
				  $("#solution_score_"+i+"").val("");
				  text = 0;
			}
			value += parseInt(text);
		}
		return value;
	}
	function confirm(){
		for(var i = 1;i<=number;i++){
			var text = $("#solution_score_"+i+"").val();
			if(!text){
				mini.alert("还有题未打分！");
				return;
			}
		}
		var url = rootPath +'/correctPapers/confirm/' + id;
		var map = new Object;
		map.score=score.toString();
		map.isPass=isPass;
		map.isCorrect=1;
		var json = JSON.stringify(map);
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{'data':json},
			success:function(data){
				if(data){
					mini.alert("操作成功");
					window.close();
				}
			}
		});
	}
	function cancle(){
		window.close();
	}
	</script>
</body>
</html>